<?php
/*
 * @Descripttion: 
 * @version: 
 * @Author: Mr. Xu
 * @Date: 2020-12-14 10:44:37
 * @LastEditors: Mr. Xu
 * @LastEditTime: 2020-12-14 16:24:18
 */
// +----------------------------------------------------------------------
// | tpcms [ WE ONLY DO WHAT IS NECESSARY ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017 http://www.tpcms.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: TPCMS < admin@tpcms.com >
// +----------------------------------------------------------------------


namespace app\admin\model;

use \think\Model;
class AdminMenu extends Model
{
	public function menulist($menu,$id=0,$level=0){
		static $menus = array();
		foreach ($menu as $value) {
			if ($value['pid']==$id) {
				$value['level'] = $level+1;
				if($level == 0)
				{
					$value['str'] = str_repeat('',$value['level']);
				}
				elseif($level == 2)
				{
					$value['str'] = '&emsp;&emsp;&emsp;&emsp;'.'└ ';
				}
				elseif($level == 3)
				{
					$value['str'] = '&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;'.'└ ';
				}
				else
				{
					$value['str'] = '&emsp;&emsp;'.'└ ';
				}
				$menus[] = $value;
				$this->menulist($menu,$value['id'],$value['level']);
			}
		}
		return $menus;
	}

	public function getTree($list, $pk = 'id', $pid = 'pid', $child = '_child', $root = 0)
	{
		$tree     = array();
		$packData = array();
		foreach ($list as $data) {
			$packData[$data[$pk]] = $data;
		}
		foreach ($packData as $key => $val) {
			if ($val[$pid] == $root) {
				//代表跟节点, 重点一
				$tree[] = &$packData[$key];
			} else {
				//找到其父类,重点二
				$packData[$val[$pid]][$child][] = &$packData[$key];
			}
		}
		return $tree;
	}
}
